package com.gym.exception;



import com.gym.utils.service.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局参数、异常拦截
 *  +----------------------------------------------------------------------
 *  | Author: xincai Team <yxhbrdc@yuanxinjituan.com>
 *  +----------------------------------------------------------------------
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {


    //声明要捕获的异常
    @ExceptionHandler(Exception.class)
    public JSONResult defaultExceptionHandler(Exception e) {
        e.printStackTrace();
        return JSONResult.errorMsg(e.getMessage());
    }

    @ExceptionHandler(MallException.class)
    public JSONResult mallExceptionHandler(MallException e) {
        e.printStackTrace();
        if(e.getCode()!=null){
            return JSONResult.error(e.getCode(),e.getMessage());
        }
        return JSONResult.errorMsg(e.getMessage());
    }






}
